<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>0</h1>
<h2>0</h2>
<script>
  let count = 0;
  //开启定时器 每隔一秒调用一次方法
  //方法作为参数进行传递的时候，不写括号
  setInterval(f,1000);
  function f() {
    count++;
    let h = document.querySelector("h1");
    h.innerText = count;
  }
  let num = 0
  //匿名方法开启定时器

  let timer =  setInterval(function () {
     num++;
      let n = document.querySelector("h2");
      n.innerText = num;
      if(num==50){
        //停止定时器
        clearInterval(timer);
      }
   },100)
  setTimeout(function () {
     alert("时间到");
  },3000)
</script>
</body>
</html>